<?php

/**
 * @author aisyah
 * @copyright 2012
 */

session_start();

include_once("../dao/database.php");
include_once("../dao/order_dao.php");

//$order = new Order_Dao();

$modul = $_GET['modul'];
$id = $_GET['id'];
$db = new Database();
$order = new Order_Dao($db);

switch($modul) {
    
    case "cart":       
        
        $order->add_cart($id);
        
    
    break;
    
    case "additem":
    
        $cat = $_GET['cat'];
        
        $order->add_cart($id,$cat);       
        
    
    break;
    
    //mengurangi jumlah barang
    case "kurang":
    
        $order->substract_cart($modul, $id);    
        
    break;
    
    //menambah jumlah barang
    case "tambah":
    
        $order->add_cart($id,null,'tambah');  
        
        
    break;
    
    //hapus list barang
    case "hapus":
    
        $order->delete_cart($id);         
        
        
    break;
    
    case "calamat":
    
        $_SESSION['alamat'] = array();
        $_SESSION['alamat']['name'] = $_POST['name'];
        $_SESSION['alamat']['street'] = $_POST['street'];
        $_SESSION['alamat']['kecamatan'] = $_POST['kecamatan'];
        $_SESSION['alamat']['city'] = $_POST['city'];
        $_SESSION['alamat']['province'] = $_POST['province'];
        $_SESSION['alamat']['zip_code'] = $_POST['zip_code'];
        
        //print_r($_SESSION['alamat']);           
        header('location:cart_view.php?modul=alamat');
        
    break;
    
    case "kirim":
    
        $_SESSION['kirim'] = $_POST['kirim'];
                           
        header('location:cart_view.php?modul=kirim');
        
    break;
    
    case "bayar":
    
        $_SESSION['bayar'] = $_POST['bayar'];
                           
        header('location:cart_view.php?modul=bayar');
        
    break;
    
    case "selesai":
    
    $tgl = date('Y-m-d');
    $customer = $order->get_customer();
    $payment = $order->get_payment();
    $po_number = $order->po_number();
    $ship_addr = $order->get_ship_addr();
    $shipping_cost = $order->get_shipping();
    $shipping = $order->shipping; 
    $order->get_subtotal();   
    $total = $order->get_total();
    $status = 1;
       
    $value = array($po_number,"$tgl",
                    $customer,
                    $payment,
                    $ship_addr,
                    $shipping,                    
                    $total,
                    $status);
    
    $row = "nomor_po,order_date, customer, payment, ship_addr, shipping, total, status";
    //print_r($row);
    //print_r($value);
    
    $db->add('corder', $value, $row);
    
    $order->to_order();
    
    $order->add_order($order->order);   
    
    
    break;
    
}